package com.proton.carepatchtemp.utils;

import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class FormUtils {
    public static String getString(TextView tvName) {
        if (tvName != null && tvName.getText() != null && tvName.getText().toString() != null) {
            return tvName.getText().toString().trim();
        }
        return "";
    }

    public static String getTagString(TextView tvName) {
        if (tvName != null && tvName.getTag() != null) {
            return String.valueOf(tvName.getTag()).trim();
        }
        return "";
    }

  /*  public static int getInt(RadioGroup rgGender) {
        int checked  = rgGender.getCheckedRadioButtonId();
        switch (checked){
            case R.deviceId.check_0:
                return 1;
            case R.deviceId.check_1:
                return 2;
        }
        return 1;
    }*/

    public static String getHeight(EditText etHeight) {
        String str = getString(etHeight);
        if (TextUtils.isEmpty(str) || str.indexOf("cm") < 1) {
            return "";
        }
        str = str.substring(0, str.indexOf("cm") - 1);
        return str;
    }

    public static String getWeight(EditText etHeight) {
        String str = getString(etHeight);
        if (TextUtils.isEmpty(str) || str.indexOf("kg") < 1) {
            return "";
        }
        str = str.substring(0, str.indexOf("kg") - 1);
        return str;
    }

/*    public static String getBirth(EditText tv) {
        if(tv!=null && tv.getTag()!=null && tv.getTag() instanceof Date && !TextUtils.isEmpty(tv.getText().toString().trim())){
            Date date = (Date) tv.getTag();
            return  FormatUtils.formatDate(date);
        }
        return "";
    }*/

    public static Date getBirthDate(EditText tv) {
        if (tv != null && tv.getTag() != null && tv.getTag() instanceof Date && !TextUtils.isEmpty(tv.getText().toString().trim())) {
            Date date = (Date) tv.getTag();
            return date;
        }
        return new Date(0);
    }

    public static String getFormLineName(String orginal) {
        int need = 0;
        if (TextUtils.isEmpty(orginal)) {
            need = 4;
        } else {
            if (orginal.length() < 4) {
                need = 4 - orginal.length();
            }
        }
        if (need > 0) {
            StringBuilder sb = new StringBuilder(orginal);
            for (int i = 0; i < need; i++) {
                sb.append("\u3000");
            }
            return sb.toString();
        }
        return orginal;
    }

    public static String formatTime(Date dealDate) {
        if (dealDate == null) {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date());
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(dealDate);
    }
}
